import configparser
import os
import socket

class ConfigUtil:
    conf = ""

    def __init__(self):
        current_hostname = socket.gethostname()
        if current_hostname == "VM-32-7-centos":
            cfgpath = "/home/data/web/conf/cfg.ini"
        else:
            cfgpath = "d:\\automobile_config\\pyconfig\\config.ini"

        # 创建管理对象
        self.conf = configparser.ConfigParser()

        # 读ini文件
        self.conf.read(cfgpath, encoding="utf-8")  # python3

    def getDB(self):
        return [self.conf.get("mysqldb","host"),
                self.conf.get("mysqldb","user"),
                self.conf.get("mysqldb","password"),
                self.conf.getint("mysqldb","port"),
                self.conf.get("mysqldb","db")
                ]

    def getTuShareKey(self):
        return self.conf.get("tushare","token")

    def getBaiduKey(self):
        return [self.conf.get("baiduapi", "name"),
                self.conf.get("baiduapi", "appid"),
                self.conf.get("baiduapi", "apikey"),
                self.conf.get("baiduapi", "secretkey")
                ]

    def getJqData(self):
        return [self.conf.get("jqdata", "user"),
                self.conf.get("jqdata", "pass")
                ]